let showData = require("./showData");

let imgPathList = ["./res/拍照_书的某页内容.jpg", "./res/某Q聊天内容截图.png"];
var len = imgPathList.length;
for (var i = 0; i < len; i++) {
  let imgPath = imgPathList[i];
  let dataList = ocr(imgPath);
  showData(dataList, imgPath, "百度");
}

function ocr(imgPath) {
  const Access_Token = "xxxxxxxxxxxxxxxxxxxxx";
  let url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=" + Access_Token;
  let img = images.read(imgPath);
  let imgBase64 = images.toBase64(img);
  console.time();
  let res = http.post(
    url,
    {
      image: imgBase64,
    },
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    }
  );
  console.timeEnd();
  return res.body.json().words_result;
}
